MEASUREMENT
COORDINATE MUTATION
TRANSFORMATION
FEATURE_CONVERSION
MISC
HELPER
RANDOM
GRIDS
AGGREGATION
META
ASSERTIONS
BOOLEANS
UNIT CONVERSION
DATA
JOINS
CLASSIFICATION

convertLength

将一个长度量的单位转换为另一个单位。支持的单位列表请参见Turf文档

函数定义

convertLength(length: number, originalUnit: string, finalUnit: string): number

参数

  • length: A number representing the length to convert, in the originalUnit.
  • originalUnit: A string representing the original unit of measurement for the length.
  • finalUnit: A string representing the final unit of measurement for the converted length.

返回值

  • 返回一个number类型的值,表示转换后的长度量。

示例

import { convertLength } from '@turf/turf';

const lengthInMile = 2.5;
const convertedLengthInKm = convertLength(lengthInMile, 'miles', 'kilometers');
console.log(convertedLengthInKm); // 4.02336

在此示例中,我们将一个用英里表示的长度量转换为公里,并将转换后的值存储在convertedLengthInKm变量中。

异常

  • 如果提供的originalUnitfinalUnit不受支持,则会抛出一个异常Unkown unit